﻿using Microsoft.Xna.Framework;
using RaptorEngine;
using RaptorEngine.Components;
using RaptorEngine.Components.CollidableComponent;

namespace OilRigSumoWrestlers.Actions
{
    internal class BarrelAction : CollisionAction
    {
        private Entity _floor;

        public BarrelAction(Entity floor)
        {
            _floor = floor;
        }

        /// <summary>
        /// Handles collision between two boundingSpheres with newton physics solid spheres and no energy wasted. 
        /// </summary>
        /// <param name="ownEntity">The parent entity of the action</param>
        /// <param name="ownVolume">The parent bounding volume of the action</param>
        /// <param name="othersEntity">The other colliding entity</param>
        /// <param name="othersVolume">The boundingVolume of the other entity</param>
        /// <param name="gameTime"></param>
        public override void HandleCollision(Entity ownEntity, BoundingVolume ownVolume, Entity othersEntity,
                                             BoundingVolume othersVolume)
        {
            if (othersEntity.HasComponent(ComponentType.Movable)
                && othersVolume.CollisionTypes.Contains((int)CollisionType.Player))
            {
                GameEngine.Instance.Audio.Play3DSound("explosion", 1f, othersEntity.Position);

                //Remove barrel
                Collidable barrel = (Collidable)ownEntity.GetComponent(ComponentType.Collidable);
                barrel.BoundingVolumes["explosion"].IsActive = true;

                ownEntity.RemoveComponent(ComponentType.Drawable3D);
                GameEngine.Instance.Scene.PeekScene().RemoveEntity(_floor);
            }
        }
    }
}
